import request from '@/utils/request';
import type { TagParam, TagAdd, TagUpdate } from '@/types/admin/tag';

export async function fetchTags(params: TagParam) {
  try {
    const res = await request.get("/admin/tag", { params });
    console.log('标签请求成功:', res);
    return res;
  } catch (error) {
    console.error('标签请求失败:', error);
    throw error;
  }
}

export async function addTag(params:TagAdd) {
  try {
    const res = await request.post("/admin/tag", { params });
    console.log('新增标签请求成功:', res);
    return res;
  } catch (error) {
    console.error('新增标签请求失败:', error);
    throw error;
  }
}

export async function updateTag(params: TagUpdate) {
  try {
    const res = await request.put("/admin/tag", { params });
    console.log('更新标签请求成功:', res);
    return res;
  } catch (error) {
    console.error('更新标签请求失败:', error);
    throw error;
  }
}

export async function deleteTag(id: string | number) {
  try {
    const res = await request.delete(`/admin/tag/${id}`);
    console.log('删除标签请求成功:', res);
    return res;
  } catch (error) {
    console.error('删除标签请求失败:', error);
    throw error;
  }
}
